﻿@{
    var KeyId = Tools.HttpHelper.Request.Query["ID"];
}

<div class="page-content animated fadeInDown" style="padding-bottom:100px;">
    <div class="container-fluid">
        <div class="row" id="form">
            <!--检索面板-->

            <div class="col-sm-6 col-md-4">
                <h4 class="example-title">用户名</h4>
                <input type="text" class="form-control" name="User_Name" data-bind="value:User_Name" placeholder="请输入用户名" />
            </div>

            <div class="col-sm-6 col-md-4">
                <h4 class="example-title">登录名</h4>
                <input type="text" class="form-control" name="User_LoginName" data-bind="value:User_LoginName" placeholder="请输入登录名" />
            </div>
            
            <div class="col-sm-6 col-md-4">
                <h4 class="example-title">登录密码</h4>
                <input type="text" class="form-control" name="User_Pwd" data-bind="value:User_Pwd" placeholder="请输入登录密码" />
            </div>

            <div class="col-sm-6 col-md-4">
                <h4 class="example-title">邮箱地址</h4>
                <input type="text" class="form-control" name="User_Email" data-bind="value:User_Email" placeholder="请输入邮件" />
            </div>

            @(UI.FindBack<Sys_RoleM, Sys_RoleM>(w => w.Role_Name, w => w.Role_ID, Url.Action("Index", "Role", new { findback = "1" }),
                                    @"admin.findBack.open('#Url','#Placeholder',function(row){App.FindBack.CallBack(row,'Role')});",
                                    "App.FindBack.CallBack(null,'Role');"
                    ))

        </div>

    </div>
</div>
<!--按钮-->
<div class="my-ButtonBar text-right">
    <div class="btn-group">
        <button type="button" class="btn btn-success btn-outline" data-bind="visible: !App.IsAdd()" onclick="adminForm.resetUrl(null)">新增</button>
        <button class="btn btn-primary btn-outline" onclick="App.Save()">提交</button>
        <button class="btn btn-danger btn-outline" onclick="admin.layer.close(admin.getLayerIframeIndex());">关闭</button>
    </div>
</div>
@section css{
}
@section js{
    <script src="~/Admin/lib/Ko/Knockout-3.4.2.debug.js"></script>
    <script src="~/Admin/js/admin-form.js"></script>
    <script type="text/javascript">
        var KeyId = '@KeyId';
        model = new vModel();
        $(function () {
            ko.applyBindings(model);//注册vModel
            App.Load();
        });

        var App = {
            IsAdd: function () {
                return !KeyId;
            },
            Load: function () {
                adminForm.load({
                    KeyId: KeyId,
                    url: "@Url.Action("Find")",
                    callBack: function (r) {

                    }
                });
            },
            Save: function () {
                adminForm.Save({
                    url: "@Url.Action("Save")"
                });
            },
            FindBack: {
                CallBack: function (row, tag, dom) {
                    if (row != null && row.length > 0) row = row[0];
                    if (tag == "Role") {
                        model.Role_ID(row ? row._ukid : "");
                        model.Role_Name(row ? row.Role_Name : "");
                    }
                }
            }
        };

        //User_ID, User_Name, User_LoginName, User_Pwd, User_Email, User_CreateTime
        function vModel() {
            @(
                 UI.CreateKOViewModel(new List<BaseEntity>() {
                 new Sys_UserM(),
                 new Sys_RoleM()
                 })
            )
            //this.User_ID = ko.observable("");
            //this.User_Name = ko.observable("");
            //this.User_LoginName = ko.observable("");
            //this.User_Pwd = ko.observable("");
            //this.User_Email = ko.observable("");

            //this.Role_ID = ko.observable("");
            //this.Role_Name = ko.observable("");
        }
    </script>
}